#include "myspiffs.h"
#include "main.h"

esp_err_t myspiffs_init(void)
{
    esp_vfs_spiffs_conf_t conf = {
        .base_path = FSROOT,
        .partition_label = NULL,
        .max_files = 5,
        .format_if_mount_failed = true};

    // Use settings defined above to initialize and mount SPIFFS filesystem.
    // Note: esp_vfs_spiffs_register is an all-in-one convenience function.
    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK)
    {
        if (ret == ESP_FAIL)
        {
            myspiffs_DEBUG("Failed to mount or format filesystem");
            myspiffs_DEBUG("spiffs初始化 错误1\r\n");
        }
        else if (ret == ESP_ERR_NOT_FOUND)
        {
            myspiffs_DEBUG("Failed to find SPIFFS partition");
            myspiffs_DEBUG("spiffs初始化 错误2\r\n");
        }
        else
        {
            myspiffs_DEBUG("spiffs初始化 错误3 %s\r\n", esp_err_to_name(ret));
        }
        return ret;
    }
    

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(NULL, &total, &used);
    if (ret != ESP_OK)
    {
        myspiffs_DEBUG("spiffs初始化 错误4(%s)\r\n", esp_err_to_name(ret));
    }
    else
    {
        myspiffs_DEBUG("spiffs初始化 total: %d, used: %d\n", total, used);
    }
    myspiffs_DEBUG("spiffs初始化 成功\r\n");
/*
    xTaskCreate(myspiffs_test_task,"myspiffs_test_task",1024*2,NULL,20,NULL);
*/
 	return ESP_OK;
}

void myspiffs_test_task(void *pvParameter)
{
	while (1) 
    {
        vTaskDelay(1000 / portTICK_PERIOD_MS); 
 	}
	vTaskDelete(NULL);
}
